#pragma once
#include "DHinge2.h"
#include "../DWorld.h"
#include "../DVector3.h"
#include "DJointGroup.h"

namespace Skill
{
	namespace Ode
	{
		namespace Joints
		{	
			void DHinge2::CollectManagedMemory()
			{
				_Anchor1 = nullptr;
				_Anchor2 = nullptr;
				_Axis1 = nullptr; 
				_Axis2 = nullptr; 
				DJoint::CollectManagedMemory();
			}

			DHinge2::DHinge2(DWorld^ world , DJointGroup^ group)
				:DJoint(world,group)
			{
				dWorldID w = world? world->_This : NULL;
				dJointGroupID g = group? group->_This : NULL;
				_SetPointer(dJointCreateHinge2(w,g),true);
			}
			DVector3^ DHinge2::Anchor1::get()
			{
				if(!_Anchor1)
					_Anchor1 = gcnew DVector3();
				dJointGetHinge2Anchor(_This,_Anchor1->_This);
				return _Anchor1;
			}
			void DHinge2::Anchor1::set(DVector3^ value)
			{
				dJointSetHinge2Anchor(_This,value->_This[0],value->_This[1],value->_This[2]);
			}

			DVector3^ DHinge2::Anchor2::get()
			{
				if(!_Anchor2)
					_Anchor2 = gcnew DVector3();
				dJointGetHinge2Anchor2(_This,_Anchor2->_This);
				return _Anchor2;
			}

			DVector3^ DHinge2::Axis1::get()
			{
				if(!_Axis1)
					_Axis1 = gcnew DVector3();
				dJointGetHinge2Axis1(_This,_Axis1->_This);
				return _Axis1;
			}
			void DHinge2::Axis1::set(DVector3^ value)
			{
				dJointSetHinge2Axis1(_This,value->_This[0],value->_This[1],value->_This[2]);
			}			

			DVector3^ DHinge2::Axis2::get()
			{
				if(!_Axis2)
					_Axis2 = gcnew DVector3();
				dJointGetHinge2Axis2(_This,_Axis2->_This);
				return _Axis2;
			}
			void DHinge2::Axis2::set(DVector3^ value)
			{
				dJointSetHinge2Axis2(_This,value->_This[0],value->_This[1],value->_This[2]);
			}


			void DHinge2::SetParam(DJointParameters parameter, dReal value)
			{
				dJointSetHinge2Param(_This,(int)parameter,value);
			}
			dReal DHinge2::GetParam(DJointParameters parameter)
			{
				return dJointGetHinge2Param(_This,(int)parameter);
			}

			
			void DHinge2::AddTorques(dReal torque1, dReal torque2)
			{
				dJointAddHinge2Torques(_This,torque1,torque2);
			}

			dReal DHinge2::Angle1::get()
			{
				return dJointGetHinge2Angle1(_This);
			}
			dReal DHinge2::Angle1Rate::get()
			{
				return dJointGetHinge2Angle1Rate(_This);
			}
			dReal DHinge2::Angle2Rate::get()
			{
				return dJointGetHinge2Angle2Rate(_This);
			}

		}
	}
}